<%@ page language="java" contentType="text/html; charset=GB18030"
    pageEncoding="GB18030"%>
<%@ page import="java.util.List" %>
<%@ page import="javax.jdo.PersistenceManager" %>
<%@ page import="com.wenjie.shoprankmonitor.User" %>
<%@ page import="com.wenjie.shoprankmonitor.Key_monitor_list" %>
<%@ page import="com.wenjie.shoprankmonitor.PMF" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB18030">
<title>Add a key on first result</title>
</head>
<body>
<%
PersistenceManager pm = PMF.get().getPersistenceManager();
String query = "select from " + User.class.getName();
List<User> user = (List<User>) pm.newQuery(query).execute();
if(user.isEmpty()) {
	%>
	<p>No result.</p>
	<%
} else {
	User u = user.get(0);
	List<Key_monitor_list> keys = u.getMonitor_keys();
	
	// ----------- list monitor ------------------
	%><p>Start display monitor...</p><%
	for (Key_monitor_list k : keys) {
		%><p><%= k.getKey_id()%>, <%=k.getKey_name()%>, <%=k.getMonitor_time()%>, <%=k.getMessage_content()%></p><%
	}
	%><p>Finish dsiplay monitor!</p><%
	// ----------- add new monitor ------------------
	%><p>Start add monitor...</p><%
	u.addKey(7l, "New one");
	%><p>Finish add monitor!</p><%
	// ------------ set variable (update) -----------------------
	%><p>Start update monitor...</p><%
	Key_monitor_list key = keys.get(keys.size() - 1);
	key.setMonitor_time();
	key.setMessage_content("Nothing");
	%><p>Finish update monitor!</p><%
	// ------------ delete variable -----------------------
	%><p>Start delete monitor...</p><%
	u.delKey(0);
	%><p>Finish delete monitor!</p><%
}
pm.close();
%>
</body>
</html>